package com.renker.blog.manage.redis.service.impl;

import java.io.UnsupportedEncodingException;
import java.util.HashSet;
import java.util.Set;

import javax.annotation.Resource;

import org.springframework.data.redis.connection.DataType;
import org.springframework.data.redis.connection.jedis.JedisConnection;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.stereotype.Service;

import com.renker.blog.manage.redis.service.IRedisService;

import redis.clients.util.SafeEncoder;

@Service
public class RedisServiceImpl implements IRedisService {
	private final static String CHARSET = "UTF-8";
	@Resource
	private JedisConnectionFactory factory;
	public Set<String> getCacheKeys(){
		JedisConnection connection = factory.getConnection();
		Set<String> strSets = new HashSet<String>();
		Set<byte[]> sets = connection.keys(SafeEncoder.encode("*"));
		for (byte[] bs : sets) {
			String key = SafeEncoder.encode(bs);
			strSets.add(key==null?"":key);
			
			long a = connection.ttl(bs);
			
			DataType type = connection.type(bs);
			System.out.println(a+"----"+type.toString());
		}
		return strSets;
	}
}
